package net.zzy.pbbot.plugin.daliyNews.controller;

import net.zzy.pbbot.util.HttpsUtils;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static net.zzy.pbbot.finalfield.Api.DALIY_NEWS_REFER;

/**
 * @author zhuZhaoYang
 * @date 2021/9/24 13:11
 */
@RestController
public class GetNewsImage {

    @GetMapping(value = "/getImage", produces = {MediaType.IMAGE_JPEG_VALUE, MediaType.IMAGE_GIF_VALUE, MediaType.IMAGE_PNG_VALUE})
    public byte[] getImage(@RequestParam String imageUrl) throws Exception {
        Map<String, String> headers = new HashMap<>();
        headers.put("Referer", DALIY_NEWS_REFER);
        return HttpsUtils.getBinary(imageUrl, null, headers);
    }
}
